package io.gitee.zhangbinhub.admin.resource.server.nami.client

import io.gitee.zhangbinhub.admin.common.api.CommonPath
import io.gitee.zhangbinhub.admin.common.api.WorkFlowApi
import io.gitee.zhangbinhub.admin.common.vo.InnerInfoVo
import io.gitee.zhangbinhub.admin.resource.server.po.ProcessHandlingPo
import io.gitee.zhangbinhub.admin.resource.server.po.ProcessStartPo
import io.gitee.zhangbinhub.admin.resource.server.po.ProcessTerminationPo
import io.gitee.zhangbinhub.admin.resource.server.vo.ProcessInstanceVo
import io.gitee.zhangbinhub.admin.resource.server.vo.ProcessTaskVo
import org.noear.nami.annotation.NamiClient
import org.noear.solon.annotation.Body
import org.noear.solon.annotation.Mapping
import org.noear.solon.annotation.Path
import org.noear.solon.core.handle.MethodType
import org.noear.solon.core.util.MimeType

@NamiClient(name = "workflow-server")
interface WorkFlowServer {
    /**
     * 获取任务信息
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + WorkFlowApi.task + "/{taskId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun getTaskInfoOpen(@Path(name = "taskId") taskId: String): ProcessTaskVo?

    /**
     * 启动流程
     */
    @Mapping(
        method = [MethodType.PUT],
        value = CommonPath.openInnerBasePath + WorkFlowApi.start,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun startInner(@Body processStartPo: ProcessStartPo): InnerInfoVo

    /**
     * 强制终止流程实例
     */
    @Mapping(
        method = [MethodType.DELETE],
        value = CommonPath.openInnerBasePath + WorkFlowApi.termination,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun terminationInner(@Body processTerminationPo: ProcessTerminationPo): InnerInfoVo

    /**
     * 启动流程
     */
    @Mapping(
        method = [MethodType.PUT],
        value = CommonPath.openInnerBasePath + WorkFlowApi.start + "/{userId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun startByUser(
        @Path(name = "userId") userId: String,
        @Body processStartPo: ProcessStartPo
    ): InnerInfoVo

    /**
     * 流程处理
     */
    @Mapping(
        method = [MethodType.POST],
        value = CommonPath.openInnerBasePath + WorkFlowApi.process + "/{userId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun processByUser(
        @Path(name = "userId") userId: String,
        @Body processHandlingPo: ProcessHandlingPo
    ): InnerInfoVo

    /**
     * 获取指定用户的待处理任务
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + WorkFlowApi.pending + "/{processInstanceId}/{userId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun pendingByUser(
        @Path(name = "processInstanceId") processInstanceId: String,
        @Path(name = "userId") userId: String
    ): List<ProcessTaskVo>

    /**
     * 获取流程实例信息
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + WorkFlowApi.instance + "/{processInstanceId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun getInstance(@Path(name = "processInstanceId") processInstanceId: String): ProcessInstanceVo?

    /**
     * 启动流程
     */
    @Mapping(
        method = [MethodType.PUT],
        value = WorkFlowApi.basePath + WorkFlowApi.start,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun start(@Body processStartPo: ProcessStartPo): InnerInfoVo
}